home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
4_10.lha
/
4_10
/
4_10b0.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
809b
|
33 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Exercise 4.10 (version 1)
/ Invert a two dimensional (n X n) array
/ using the Gauss-Jordan elimination method.
/ Return 1 if succeeded, 0 if singular.
include <swap.h>
/ Find A[i][d] which is non zero, i >= d,
/ and swap with A[d][d].
/ Return FALSE if there are no non-zero entries.
tatic int dopivot(double **A, double **I,
int diag, int nelem)
if (A[diag][diag] != 0.0)
return 1;
for (int i = diag+1; i < nelem; i++)
if (A[i][diag] != 0.0)
{
// swap row i with row diag in A and I
swap(A[diag], A[i]);
swap(I[diag], I[i]);
break;
}
// if no non-zero entries (i == nelem),
// then failure
return i < nelem;